package com.none.web.controller.mycorner;



import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;



import org.springframework.web.bind.annotation.ResponseBody;

import spring.mvc.bind.annotation.FormModel;

import com.none.core.common.utils.JSONUtil;
import com.none.core.model.Pager;
import com.none.core.model.Result;
import com.none.web.common.SysConstant;
import com.none.web.service.mycorner.IMyCornerService;

/**
 * My Corner管理Controller
 * 
 * @author Summer
 * 
 */
@Controller
@RequestMapping("myCorner")
public class MyCornerController {

	@Resource(name = "cornerService")
	IMyCornerService cornerService;
	@Autowired
	private HttpServletRequest request;
	/**
	 * 获取报过名的活动(只获取最新的3条数据)
	 * @param userId  当前App端登录人
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("getRegActivity")
	public Object getRegActivity(String userId) throws Exception {
		if(userId==null||userId.equals("")){
			userId = request.getHeader("BasicAuthUsername");
		}

		String[] filter = new String[] { "activitys", "TNewses","tcodes","appUsers", "password"};
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("ActivityList", cornerService.getRegActivity(userId));
		
		data.put("showmore", cornerService.getShowMoreFlag(userId,"activity"));
		Result result = new Result(SysConstant.STATE_SUCCESS, "activity.funcSuccess", data);
		return JSONUtil.toJSON(result, filter);
	}
	
	/**
	 * 获取报过名的活动
	 * @param userId  当前App端登录人
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("getAllRegActivity")
	public Object getAllRegActivity(@FormModel("pager") final Pager pager,String userId) throws Exception {
		if(userId==null||userId.equals("")){
			userId = request.getHeader("BasicAuthUsername");
		}

		String[] filter = new String[] { "activitys", "TNewses","tcodes","appUsers", "password"};
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("ActivityList", cornerService.getAllRegActivity(pager,userId));
		data.put("pager", pager);
		Result result = new Result(SysConstant.STATE_SUCCESS, "activity.funcSuccess", data);
		return JSONUtil.toJSON(result, filter);
	}
	
	
	/**
	 * 获取点过赞的活动、新闻(只获取最新的3条数据)
	 * @param userId  当前App端登录人
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("getLikeArticles")
	public Object getLikeArticles(String userId) throws Exception {
		if(userId==null||userId.equals("")){
			userId = request.getHeader("BasicAuthUsername");
		}

		String[] filter = new String[] { "TBeacons", "TNewses", "password", "tcodes","lastTime","activitys","appUsers"};
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("ArticlesList", cornerService.getLikeArticles(userId));
		data.put("showmore", cornerService.getShowMoreFlag(userId,"articles"));
		Result result = new Result(SysConstant.STATE_SUCCESS, "activity.funcSuccess", data);
		return JSONUtil.toJSON(result, filter);
	}
	
	/**
	 * 获取报过名的活动
	 * @param userId  当前App端登录人
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("getAllLikeArticles")
	public Object getAllLikeArticles(@FormModel("pager") final Pager pager,String userId) throws Exception {
		if(userId==null||userId.equals("")){
			userId = request.getHeader("BasicAuthUsername");
		}

		String[] filter = new String[] { "TBeacons", "TNewses", "password", "tcodes","lastTime","activitys","appUsers"};
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("ArticlesList", cornerService.getAllLikeArticles(pager,userId));
		data.put("pager", pager);
		Result result = new Result(SysConstant.STATE_SUCCESS, "activity.funcSuccess", data);
		return JSONUtil.toJSON(result, filter);
	}
}
